/*
 * @description: 
 * @Author: zoumingyin
 * @Date: 2020-05-19 21:36:08
 * @LastEditors: zoumingyin
 * @LastEditTime: 2020-06-04 22:15:30
 */ 
import React, { Component } from 'react';
import Item from '../Item' 
class Content extends Component {
  constructor(){
    super();
    this.state={
      data:[]
    }
  }
  componentDidMount(){
    fetch("/mock/list.json").then(res => {
      if(res.ok){
        res.json().then(result => { 
          this.setState({
            data:result.list
          })
 
        })
      }
    })
    
  }
  render() {
    return (
      <div>
        {this.state.data.map(item =>{
          return     <Item key={item.id} data={item}
                      submit={this.handSubmit}/>
        })}
    
      </div>
    );
  }
  handSubmit = (id,content,stars,state)=>{
  const newData=  this.state.data.map((item) => {
      debugger
      return item.id===id ?{
        ...item,content,stars,state:true
      }:item
    })
    this.setState({
      data:newData
    })
  };

}

export default Content;